package com.edu.exam.enums;

/**
 * 会话配置类型枚举
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-12
 */
public enum SessionConfigType {
    EXAM_PARAMS("EXAM_PARAMS", "考试参数"),
    FEATURE_SWITCHES("FEATURE_SWITCHES", "功能开关"),
    SECURITY_SETTINGS("SECURITY_SETTINGS", "安全设置"),
    DISPLAY_CONFIG("DISPLAY_CONFIG", "显示配置"),
    SYSTEM_CONFIG("SYSTEM_CONFIG", "系统配置"),
    USER_CONFIG("USER_CONFIG", "用户配置"),
    OTHER("OTHER", "其他配置");

    private final String code;
    private final String description;

    SessionConfigType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static SessionConfigType fromCode(String code) {
        for (SessionConfigType type : SessionConfigType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown session config type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static SessionConfigType fromDescription(String description) {
        for (SessionConfigType type : SessionConfigType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown session config type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}